﻿using AnQinFrameWorkAPI.Entity.SystemCore.DTO.CodeRule;
using AnQinFrameWorkAPI.Entity.SystemCore.DTO.Menu;
using AnQinFrameWorkAPI.Entity.SystemCore.DTO.MenuBotton;
using AnQinFrameWorkAPI.Entity.SystemCore.DTO.MenuField;
using AnQinFrameWorkAPI.Entity.SystemCore.DTO.Role;
using AnQinFrameWorkAPI.Entity.SystemCore.DTO.SystemConfig;
using AnQinFrameWorkAPI.Entity.SystemCore.Entity;
using AnQinFrameWorkAPI.Entity.SystemCore.View.CodeRule;
using AnQinFrameWorkAPI.Entity.SystemCore.View.Menu;
using AnQinFrameWorkAPI.Entity.SystemCore.View.MenuButton;
using AnQinFrameWorkAPI.Entity.SystemCore.View.MenuField;
using AnQinFrameWorkAPI.Entity.SystemCore.View.Role;
using AnQinFrameWorkAPI.Entity.SystemCore.View.RoleButton;
using AnQinFrameWorkAPI.Entity.SystemCore.View.RoleField;
using AnQinFrameWorkAPI.Entity.SystemCore.View.RoleMenu;
using AnQinFrameWorkAPI.Entity.SystemCore.View.SystemConfig;
using AutoMapper;

namespace AnQinFrameWorkAPI.Common.Mapper;

public class SystemCoreMapper : Profile
{
    public SystemCoreMapper()
    {
        //全局配置
        CreateMap<Guid?, string>().ConvertUsing(src =>
            src == null || src == Guid.Empty ? null : src.Value.ToString());

        #region 系统

        #region 菜单管理

        CreateMap<MenuAddDTO, MenuModel>();
        CreateMap<MenuUpdateDTO, MenuModel>();
        CreateMap<MenuModel, RoleMenuView>();
        CreateMap<MenuModel, MenuView>()
            .ForMember(a => a.SuperiorName,
                opt => opt.MapFrom(src => src.Menu.Name));
        CreateMap<MenuModel, MenuDetailView>()
            .ForMember(a => a.SuperiorName,
                opt => opt.MapFrom(src => src.Menu.Name))
            .ForMember(a => a.MenuButtonList,
                opt => opt.MapFrom(src => src.MenuButtonList
                    .Select(b => b.Key)
                    .ToArray()))
            .ForMember(a => a.MenuFieldList,
                opt => opt.MapFrom(src => src.MenuFieldList
                    .Select(b => b.Key)
                    .ToArray()));

        #endregion

        #region 菜单按钮

        CreateMap<MenuButtonAddDTO, MenuButtonModel>();
        CreateMap<MenuButtonUpdateDTO, MenuButtonModel>();
        CreateMap<MenuButtonModel, MenuButtonView>();

        #endregion

        #region 菜单字段

        CreateMap<MenuFieldAddDTO, MenuFieldModel>();
        CreateMap<MenuFieldUpdateDTO, MenuFieldModel>();
        CreateMap<MenuFieldModel, MenuFieldView>();

        #endregion

        #region 编码规则

        CreateMap<CodeRuleAddDTO, CodeRuleModel>();
        CreateMap<CodeRuleUpdateDTO, CodeRuleModel>();
        CreateMap<CodeRuleItemAddDTO, CodeRuleItemModel>();
        CreateMap<CodeRuleItemUpdateDTO, CodeRuleItemModel>();
        CreateMap<CodeRuleModel, CodeRuleView>();
        CreateMap<CodeRuleModel, CodeRuleDetailView>();
        CreateMap<CodeRuleItemModel, CodeRuleItemView>();

        #endregion

        #region 角色管理

        CreateMap<RoleAddDTO, RoleModel>();
        CreateMap<RoleUpdateDTO, RoleModel>();
        CreateMap<RoleModel, RoleView>();

        #endregion

        #region 角色菜单

        CreateMap<RoleMenuModel, RoleMenuView>();

        #endregion

        #region 角色按钮

        CreateMap<RoleButtonModel, RoleButtonView>();

        #endregion

        #region 角色字段

        CreateMap<RoleFieldModel, RoleFieldView>();

        #endregion

        #region 全局配置

        CreateMap<SystemConfigAddDTO, SystemConfigModel>();
        CreateMap<SystemConfigUpdateDTO, SystemConfigModel>();
        CreateMap<SystemConfigModel, SystemConfigView>();

        #endregion

        #endregion
    }
}